package com.woorigil.social.domain.deal.repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.woorigil.social.domain.CouponSqlMapDaoSupport;
import com.woorigil.social.domain.deal.Deal;

@Repository
public class DealListDao extends CouponSqlMapDaoSupport<Deal, Integer> {
	public static final String NAMESPACE = "DealList";
	
	@Override
	public String getNamespace() {
		return NAMESPACE;
	}

	public int selectCategoryTotalCount(DealListCondition condition) {
		Object result = getSqlMapClientTemplate().queryForObject(getStatementName(NAMESPACE, "selectCategoryTotalCount"), condition);
		return (result == null)? 0 : (Integer)result;
	}

	@SuppressWarnings("unchecked")
	public List<Deal> selectCategoryList(DealListCondition condition) {
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "selectCategoryList"), condition);
	}
	
	@SuppressWarnings("unchecked")
	public List<Deal> selectDistanceList(DealListCondition condition) {
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "selectDistanceList"), condition);
	}

	public int selectNewTotalCount(DealListCondition condition) {
		Object result = getSqlMapClientTemplate().queryForObject(getStatementName(NAMESPACE, "selectNewTotalCount"), condition);
		return (result == null)? 0 : (Integer)result;
	}

	@SuppressWarnings("unchecked")
	public List<Deal> selectNewList(DealListCondition condition) {
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "selectNewList"), condition);
	}
	
	@SuppressWarnings("unchecked")
	public List<Deal> selectEndList(DealListCondition condition) {
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "selectEndList"), condition);
	}

//	public int selectFreeTotalCount(DealListCondition condition) {
//		Object result = getSqlMapClientTemplate().queryForObject(getStatementName(NAMESPACE, "selectFreeTotalCount"), condition);
//		return (result == null)? 0 : (Integer)result;
//	}

	@SuppressWarnings("unchecked")
	public List<Deal> selectFreeList(DealListCondition condition) {
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "selectFreeList"), condition);
	}

	@SuppressWarnings("unchecked")
	public List<Deal> search(DealListCondition condition) {
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "search"), condition);
	}
	
	@SuppressWarnings("unchecked")
	public List<Deal> selectAllByMainCategory(int mainCategoryId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("mainCategoryId", mainCategoryId);
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "selectAllSimpleList"), params);
	}
}
